<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String gd_content_code = request.getParameter("gd_content_code") == null ? "" : request.getParameter("gd_content_code");
    String gd_content_id = request.getParameter("gd_content_id") == null ? "" : request.getParameter("gd_content_id");
    String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
    String gd_type = request.getParameter("gd_type") == null ? "" : request.getParameter("gd_type");

    boolean isAdd = "1".equals(gd_content_code);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>
<html>
	<head>
		<title><%=isAdd?"新建工单":"编辑工单" %></title>
		<link href="<%=contextPath%>/public/css/smart_wizard_vertical.css" rel="stylesheet"	type="text/css">
		<script type="text/javascript" src="<%=contextPath%>/public/js/jquery.smartWizard.js"></script>
		<link  rel="stylesheet"  href  ="<%=contextPath%>/public/swfupload/css/swfupload.css">
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/datastructs.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/sys.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/prototype.js"  ></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/attachMenu.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/Menu.js"></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/fileprogress.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/handlers.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.queue.js"  ></script>
		<script type="text/javascript">
			var typeArr=new Array("内部班组","外部分包商");
			var swfupload;
			var flag = '<%=flag%>';
			var gdAdminId="";
			var gdAdminName="";
			var customerId="";
			var customerName="";
			var fbId="";
			var fbName="";
			jQuery(document).ready(function() {
				if(flag == '1'){
					jQuery('#gdForm').form({
						onLoadSuccess:function(data){
							queueCompleteOver();
							gdAdminId=data.gd_admin_id;
							gdAdminName=data.gd_admin_name;
							customerId=data.customer_id;
							customerName=data.customer;
							fbId=data.gd_worker_id;
							fbName=data.gd_worker_name;
						}
					});
				}
				jQuery('#gdForm').form("load",'<%=contextPath %>/springMVC/gd/getGDBaseBgById?gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>');
				
				jQuery("#searchValue").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearch();
			       	} 
			   	}); 
				jQuery("#searchValue1").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearch1();
			       	} 
			   	}); 
				jQuery("#searchValuec").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearchc();
			       	} 
			   	}); 
				
					jQuery("#customer_type_id").combotree({
						url:'<%=contextPath%>/springMVC/group/getSystemTypeTree?type=1',
						method:'POST',
						animate:true,
						lines:true,
						onChange:function(){
							doSearchc();
						}
					});
					
				jQuery('#customer_id').combogrid({
					title:'客户选择',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/crm/listPageCustomer",
					idField:"id",
					textField:"company",
					disabled:'disabled',
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{title:'客户类别',field:'type_name',width:200,align:'center'},
						{title:'公司名称',field:'company',width:200,align:'center'},
						{title:'联系人',field:'contact',width:200,align:'center'},
						{title:'TEL',field:'tel',width:200,align:'center'}
					]],
					toolbar:"#tbc",
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onLoadSuccess:function(rtJson){
						jQuery('#customer_id').combogrid('setValue',customerId);
						jQuery('#customer_id').combogrid('setText',customerName);
					}
				});
				jQuery('#gd_admin_id').combogrid({
					title:'人员选择',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					disabled:'disabled',
					url:"<%=contextPath%>/springMVC/group/listPageUser",
					idField:"id",
					textField:"truename",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{field:'deptId',hidden:true},
						{field:'truename',title:'姓名',width:100},
						{field:'deptName',title:'所属部门',width:100},
						{field:'privName',title:'角色',width:100}
					]],
					toolbar:"#tb",
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onChange:function(){
						var row = jQuery('#gd_admin_id').combogrid("grid").datagrid('getSelected');
						jQuery('#dept_id').val(row.deptId);
						jQuery('#dept_name').val(row.deptName);
					},
					onLoadSuccess:function(rtJson){
						jQuery('#gd_admin_id').combogrid('setValue',gdAdminId);
						jQuery('#gd_admin_id').combogrid('setText',gdAdminName);
					}
				});
				jQuery('#gd_worker_id').combogrid({
					idField:"id",
					textField:"worker_company",
					title:'分包商资料',
					panelWidth:550,
					panelHeight:400,
					rownumbers:true,
					disabled:'disabled',
					url:'<%=contextPath%>/springMVC/crm/listPageWorker',
					loadMsg:'正在加载数据，请稍后......',
					fitColumns:true,
					frozenColumns:[[
					    {title:'主键',field:'id',hidden:true}
					]],
					columns:[[
						{title:'分包商类别',field:'type_id',width:200,align:'center',formatter:function(value,rowData,rowIndex){
							return typeArr[rowData.type_id];
						}},
						{title:'公司名称',field:'worker_company',width:200,align:'center'},
						{title:'负责人',field:'worker_person',width:200,align:'center'},
						{title:'联系方式',field:'contact',width:200,align:'center'}
					]],
					pageSize:10,
					pageList : [10,50,100],  
					pagination:true,
					toolbar:'#tb1',
					onChange:function(){
						var row = jQuery('#gd_worker_id').combogrid("grid").datagrid('getSelected');
						jQuery('#gd_worker_person').val(row.worker_person);
					},
					onLoadSuccess:function(rtJson){
						jQuery('#gd_worker_id').combogrid('setValue',fbId);
						jQuery('#gd_worker_id').combogrid('setText',fbName);
					}
				});
					
					var settings = {
				      flash_url : "<%=contextPath%>/public/swfupload/swfupload.swf",
				      upload_url: "<%=contextPath%>/springMVC/fileUpload/fileupload",
				      post_params: {
				    	 "module" : "<%=com.beaut.project.util.StaticData.GD_MODULE%>"
				      },
				      file_size_limit : "100 MB",
				      file_types : "*.*",
				      file_types_description : "All Files",
				      file_upload_limit : 100,
				      file_queue_limit : 0,
				      custom_settings : {
				        uploadArea : "fsUploadArea",
				        progressTarget : "fsUploadProgress",
				        startButtonId : "btnStart",
				        cancelButtonId : "btnCancel"
				      },
				      debug: false,
				      button_image_url: "<%=contextPath%>/public/swfupload/img/uploadx4.gif",
				      button_width: "65",
				      button_height: "29",
				      button_placeholder_id: "spanButtonUpload",
				      button_text: '<span class=\"textUpload\">上传附件</span>',
				      button_text_style: ".textUpload{color:#0000ff;}",
				      button_text_top_padding : 1,
				      button_text_left_padding : 18,
				      button_width: 80,
				      button_height: 20,
				      button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				      button_cursor: SWFUpload.CURSOR.HAND,
				      
				      file_queued_handler : fileQueued,
				      file_queue_error_handler : fileQueueError,
				      file_dialog_complete_handler : fileDialogComplete,
				      upload_start_handler : uploadStart,
				      upload_progress_handler : uploadProgress,
				      upload_error_handler : uploadError,
				      upload_success_handler : uploadSuccessOver,
				      upload_complete_handler : uploadComplete,
				      queue_complete_handler : queueCompleteOver
				    };
				    swfupload = new SWFUpload(settings);
				    
				});
			
		 function uploadSuccessOver(file, serverData){
				  try {
				    var progress = new FileProgress(file, this.customSettings.progressTarget);
				    progress.toggleCancel(false);
				    var json = null;
				    json = serverData.evalJSON();
				    if(json.rtState=="1") {
				       progress.setError();
				       progress.setStatus("上传失败");
				    } else {
				       if($('attachmentId').value!=null && $('attachmentId').value!=""){
				    	 $('attachmentId').value += ',' + json.rtData.attachmentId;
				       } 
				       else{
				    	   $('attachmentId').value = json.rtData.attachmentId;
				       }
				       if($('attachmentName').value!=null && $('attachmentName').value!=""){
				    	 $('attachmentName').value += '*' + json.rtData.attachmentName;
				       } 
				       else{
				    	   $('attachmentName').value = json.rtData.attachmentName;
				       }
				    }
				  } catch (ex) {
				    this.debug(ex);
				  }
		}
		function queueCompleteOver(){
			var attachmentIds = $("attachmentId").value;
		    var attachmentNames = $("attachmentName").value;
		    if(attachmentIds){
		      jQuery('#attaTr').show();
	       	  jQuery('#fsUploadArea').hide();
	       	  attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,false,'attach');
		    }
		 }
				 
		  function deleteAttachment(attachmentId,attachmentName){
			  var attrIds = $("attachmentId").value;
		    var attrNames = $("attachmentName").value;
		     var attrIdArrays = attrIds.split(",");
			  var attrNameArrays = attrNames.split("*");
			 var idArray = new Array();
			 var nameArray = new Array();
			 
			 for(var i=0;i<attrIdArrays.length;i++){
				 if(attrIdArrays[i] != attachmentId){
					 idArray.push(attrIdArrays[i]);
					 nameArray.push(attrNameArrays[i]);
				 }
			 }
			 $("attachmentId").value = idArray.join(",");
			 $("attachmentName").value = nameArray.join("*");
			 if($("attachmentId").value == ""){
				 jQuery('#attaTr').hide();
			 }
		  }
		  
		
		  
		  function doSubmit() {			 
				//工单基本属性
			  var customer_id = jQuery('#customer_id').combogrid('getValue');
			  var customer = jQuery('#customer_id').combogrid('getText');
			   var xm_id = jQuery('#xm_id').val();
			  var xm_name = jQuery('#xm_name').val();
			  var xm_code = jQuery('#xm_code').val();
			  var gd_code = jQuery('#gd_code').val();
			  var gd_name = jQuery('#gd_name').val();
			  var gd_depand_id = jQuery('#gd_depand_id').combobox('getValue');
			  var gd_depand_name = jQuery('#gd_depand_id').combobox('getText');
			  var gd_sender = jQuery('#gd_sender').val();
			  var gd_notice_time=jQuery('#gd_notice_time').datebox('getValue');
			  var gd_admin_id=jQuery('#gd_admin_id').combogrid('getValue');
			  var gd_admin_name=encodeURIComponent(jQuery('#gd_admin_id').combogrid('getText'));
			  var dept_id = jQuery('#dept_id').val();
			  var dept_name = jQuery('#dept_name').val();
			  var gd_content = encodeURIComponent(jQuery('#gd_content').val());
			  var gd_detail_type_name = jQuery('#gd_detail_type_name').val();
			  var gd_total_time = jQuery('#gd_total_time').numberbox('getValue');
			  var gd_start=jQuery('#gd_start').datebox('getValue');
			  var gd_will_end=jQuery('#gd_will_end').datebox('getValue');
			  var gd_worker_id = jQuery('#gd_worker_id').combogrid('getValue');
			  var gd_worker_name = jQuery('#gd_worker_id').combogrid('getText');
			  var gd_worker_person = jQuery('#gd_worker_person').val();
			  var attachmentId = jQuery('#attachmentId').val();
			  var alarm_time = jQuery('#alarm_time').datebox('getValue');
			var param = "customer_id="+customer_id+"&customer="+customer+"&xm_id="+xm_id+"&xm_code="+xm_code+"&xm_name="+xm_name+"&gd_code="+gd_code+"&gd_name="+gd_name
					   +"&gd_depand_id="+gd_depand_id+"&gd_depand_name="+gd_depand_name+"&gd_sender="+gd_sender+"&gd_notice_time="+gd_notice_time
					   +"&gd_admin_id="+gd_admin_id+"&gd_admin_name="+gd_admin_name+"&dept_id="+dept_id+"&dept_name="+dept_name
					   +"&gd_content="+gd_content+"&gd_detail_type_name="+gd_detail_type_name+"&gd_total_time="+gd_total_time+"&gd_start="+gd_start
					   +"&gd_will_end="+gd_will_end+"&gd_worker_id="+gd_worker_id+"&gd_worker_name="+gd_worker_name+"&gd_worker_person="+gd_worker_person
					   +"&attachmentId="+attachmentId+"&alarm_time="+alarm_time+"&gd_type=<%=gd_type%>";
			jQuery.ajax({
				type:'POST',
			  	<%=isAdd?"url:'"+contextPath+"/springMVC/gd/addGDBgMain?gd_id="+gd_id+"',":"url:'"+contextPath+"/springMVC/gd/updateGDBgMain?gd_id="+gd_id+"&gd_content_id="+gd_content_id+"',"%>
				data:param,
				success:function(rtJson){
					if (rtJson.rtState == '0'){
						eval('window.opener.<%=callback%>();');
						window.close();
					}else{
						warningInfo(rtJson.rtMsrg);
					}
				}
			});
		}
		  function doSearchc()
			{
				var searchValue = jQuery('#searchValuec').val();
				var type_id = jQuery('#customer_type_id').combotree('getValue');
				jQuery('#customer_id').combogrid("grid").datagrid('load',{
					searchValue:searchValue,
					type_id:type_id
				});
			}
		</script>
	</head>
	<body>
		
						<div id="step-1" style="width:100%;hight:510px" align="center">
							<form id="gdForm">
							<table  style="border-collapse: collapse;"  border="1px" bordercolor="#0eb83a" >
								<tr>
									 <td align="right" nowrap class="td1">
										客户：
									</td>
									<td class="td2" nowrap>
										<input id="customer_id" name="customer_id"  data-options="required:true">
									</td>
									<td align="right" nowrap class="td1">
										工单依据：
									</td>
									<td class="td2" nowrap >
										<input id="gd_depand_id"  name="gd_depand_id" class="easyui-combobox" data-options="disabled:'disabled',required:true,valueField:'id',textField:'text',url:'<%=contextPath %>/springMVC/group/getSystemTypeBox?type=3'" /> 
									</td>
								</tr>
								<tr>
									 <td align="right" nowrap class="td1">
										项目名称：
									</td>
									<td class="td2" nowrap>
										<input type="hidden" id="xm_id" name="xm_id"  >
										<input type="text" id="xm_name" name="xm_name" readOnly >
									</td>
								  <td align="right" nowrap class="td1">
										项目编号：
									</td>
									<td class="td2" nowrap>
										<input type="text" id="xm_code" name="xm_code" readonly="readonly">
									</td>
								</tr>
								<tr>
									 <td align="right" nowrap class="td1">
										工单名称：
									</td>
									<td class="td2" nowrap>
										<input type="text" id="gd_name" name="gd_name" class="easyui-validatebox" readonly="readonly" data-options="required:true">
									</td>
								  <td align="right" nowrap class="td1">
										工单编号：
									</td>
									<td class="td2" nowrap>
										<input type="text" id="gd_code" name="gd_code" class="easyui-validatebox" readonly="readonly" data-options="required:true">
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										派单人：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_admin_id" name="gd_admin_id" readonly="readonly" data-options="required:true">
									</td>
									<td align="right"  nowrap class="td1">
										所属部门：
									</td>
									<td class="td2" nowrap >
										<input type="hidden" id="dept_id" name="dept_id">
										<input type="text" id="dept_name" name="dept_name" readOnly>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										发包人：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_sender" name="gd_sender"  class="easyui-validatebox" readonly="readonly" data-options="required:true">
									</td>
									<td align="right"  nowrap class="td1">
										通知日期：
									</td>
									<td class="td2" nowrap >
										<input id="gd_notice_time" name="gd_notice_time" class="easyui-datebox" data-options="required:true,disabled:'disabled'"/>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										主要工作量及实施要求：
									</td>
									<td class="td2" nowrap colspan="3">
										<textarea id="gd_content" name="gd_content" class="easyui-validatebox" data-options="required:true" style="height:100%;width:100%" rows="6"></textarea>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										细分专业：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_detail_type_name" name="gd_detail_type_name" readonly="readonly" class="easyui-validatebox" data-options="required:true"/>
									</td>
									<td align="right"  nowrap class="td1">
										总工时数：
									</td>
									<td class="td2" nowrap >
										<input id="gd_total_time" name="gd_total_time" class="easyui-numberbox" data-options="min:0,precision:3" value="0"/>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										要求工期：
									</td>
									<td class="td2" nowrap >
										<input id="gd_start" name="gd_start" class="easyui-datebox" required="required"/>
									</td>
									<td align="right"  nowrap class="td1" style="text-align:center;font-size: 20px;font-weight: bold;">
										至
									</td>
									<td class="td2" nowrap >
										<input id="gd_will_end" name="gd_will_end" class="easyui-datebox" required="required"/>
									</td>
									
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										预警时间：
									</td>
									<td class="td2" nowrap >
										<input id="alarm_time" name="alarm_time" class="easyui-datebox" required="required"/>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										收单单位：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_worker_id" name="gd_worker_id"    data-options="required:true">
									</td>
									<td align="right"  nowrap class="td1">
										实施负责人：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_worker_person" name="gd_worker_person"   class="easyui-validatebox" data-options="required:true">
									</td>
								</tr>
									<tr id="attaTr" style="display:none">
								      <td nowrap class="td1">附件明细: </td>
								      <td class="td2" colspan='3'>
								        <input type="hidden" id="attachmentId" name="attachmentId">
								        <input type="hidden" id="attachmentName" name="attachmentName">
								        <span id="showAtt">
								        </span>
								      </td>
							   	    </tr>
								<tr>
							      <td nowrap class="td1">附件：</td>
							      <td class="td2" colspan='3'>
							        	 <div id="fsUploadArea" class="flash" style="width:380px;">
										     <div id="fsUploadProgress"></div>
										     <div>
										       <input type="button" id="btnStart" class="SmallButtonW" value="开始上传" onclick="swfupload.startUpload();" disabled="disabled">&nbsp;&nbsp;
										       <input type="button" id="btnCancel" class="SmallButtonW" value="全部取消" onclick="javascript:swfupload.cancelQueue();jQuery('#fsUploadArea').hide();" disabled="disabled">&nbsp;&nbsp;
										    </div>
									      </div>
									      
										    <div id="attachment1">
									          <span id="spanButtonUpload" title="上传附件"></span>
									        </div>
							      </td>
					   		   </tr>
					   		    <tr>
								<td align="right" nowrap class="td1">
								</td>
								<td  nowrap colspan="5">
									<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="doSubmit(this);">保存</a>
									<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
								</td>
							</tr>
				 			</table>
				 			</form>
						
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
		<div id="tb1" style="padding:3px;height:auto">
			<div align="right">
				分类：<select id="type_id" class="" name="type_id"  onchange="doSearch1()">   
					     <option value="" selected></option> 
					    <option value="0">内部班组</option>   
					    <option value="1">外部分包商</option>   
					</select>  
				查询条件：<input id="searchValue1" name="searchValue1" style="width:150px" title="分包商名称或负责人"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch1();"></a>
			</div>
		</div>
		<div id="tbc" style="padding:3px;height:auto">
			<div align="right">
				分类：<input  id="customer_type_id" name="customer_type_id" class="easyui-combotree">
				查询条件：<input id="searchValuec" name="searchValuec" style="width:150px" title="客户名称或联系人"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearchc();"></a>
			</div>
		</div>
	</body>
</html>


